using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;

namespace Blazing.Web.Modules
{
    public enum RewriteTypes
    {
        Rewrite,
        Redirect
    }

    public class PostRequestConfig : ConfigurationSection
    {
        [ConfigurationProperty("RewriterRules")]
        public UrlRuleCollection UrlRules
        {
            get { return (UrlRuleCollection)this["RewriterRules"]; }
            set { this["RewriterRules"] = value; }
        }
    }

    public class UrlRuleCollection : ConfigurationElementCollection
    {
        protected override ConfigurationElement CreateNewElement()
        {
            return new UrlRule();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((UrlRule)element).Url;
        }
    }

    public class UrlRule : ConfigurationElement
    {
        [ConfigurationProperty("key", IsKey=true, IsRequired=true)]
        public string Url
        {
            get { return (string)this["key"]; }
            set { this["key"] = value; }
        }

        [ConfigurationProperty("value", IsRequired = true)]
        public string Rewrite
        {
            get { return (string)this["value"]; }
            set { this["value"] = value; }
        }

        [ConfigurationProperty("StatusCode", DefaultValue = 302)]
        public int StatusCode
        {
            get { return (int)this["StatusCode"]; }
            set { this["StatusCode"] = value; }
        }

        [ConfigurationProperty("RewriteType",DefaultValue=RewriteTypes.Rewrite)]
        public RewriteTypes RewriteType
        {
            get { return (RewriteTypes)this["RewriteType"]; }
            set { this["RewriteType"] = value; }
        }

        [ConfigurationProperty("AppendHostAsQueryParam", DefaultValue = false)]
        public bool AppendHostAsQueryParam
        {
            get { return (bool)this["AppendHostAsQueryParam"]; }
            set { this["AppendHostAsQueryParam"] = value; }
        }
    }
}
